module.exports = (app) => {
  const { STRING, DATE, INTEGER, TEXT } = app.Sequelize
  const Comment = app.model.define('comment', {
    id: {
      type: INTEGER(20).UNSIGNED,
      primaryKey: true,
      autoIncrement: true,
      comment: '主键id'
    },
    content: {
      type: TEXT,
      allowNull: false,
      comment: '评论内容'
    },
    article_id: {
      type: INTEGER(20).UNSIGNED,
      allowNull: false,
      comment: '文章id',
      references: {
        model: 'article',
        key: 'id'
      },
      onUpdate: 'restrict', // 更新时操作
      onDelete: 'cascade' // 删除时操作
    },
    username: {
      type: STRING(20),
      allowNull: false,
      comment: '评论用户'
    },
    avatar: {
      type: STRING(255),
      allowNull: false,
      comment: '评论用户头像'
    },
    status: {
      type: INTEGER(1),
      allowNull: false,
      defaultValue: 1,
      comment: '评论状态 0:已删除 1:正常'
    },
    created_at: {
      type: DATE,
      get() {
        return new Date(this.getDataValue('created_at')).getTime()
      }
    },
    updated_at: DATE
  })
  return Comment
}
